package com.guguskins.back.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guguskins.back.common.constant.RedisConstant;
import com.guguskins.back.entity.GuSystemConfig;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuSystemConfigService;
import com.guguskins.back.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/systemConfig")
public class GuSystemConfigController {
    @Autowired
    private GuSystemConfigService systemConfigService;

    @GetMapping("/agreement")
    public ResultVo agreement() {
        String agreement = systemConfigService.getObj(new LambdaQueryWrapper<GuSystemConfig>() {
            {
                select(GuSystemConfig::getConfigUserAgreement);
                eq(GuSystemConfig::getConfigId, 1);
            }
        }, Object::toString);
        return ResultVo.success((Object) agreement);
    }
    @GetMapping("/exchangeRate")
    public ResultVo detail() {
        BigDecimal exchangeRate = systemConfigService.getObj(new LambdaQueryWrapper<GuSystemConfig>() {
            {
                select(GuSystemConfig::getConfigExchangeRate);
                eq(GuSystemConfig::getConfigId, 1);
            }
        }, o -> new BigDecimal(o.toString()));
        return ResultVo.success(exchangeRate);
    }
    @GetMapping("/back/detail")
    public ResultVo backDetail() {
        GuSystemConfig systemConfig = systemConfigService.getById(1);
        return ResultVo.success(systemConfig);
    }
    @PostMapping("/back/edit")
    public ResultVo backEdit(@RequestBody GuSystemConfig systemConfig) {
        if(systemConfigService.backEdit(systemConfig)) {
            return ResultVo.success("修改成功");
        }
        return ResultVo.fail("修改失败");
    }
    @GetMapping("radio")
    public ResultVo radio()
    {
        return ResultVo.success(systemConfigService.getOne(null),"success");
    }
}
